<?php

namespace plugins\rwechat\controller;

class AdminWechatUserController extends Controller
{
    public function index()
    {
        $list = $this->wxapp()->user->list();
        $list = $this->wxapp()->user->select($list['data']['openid']);
        $this->assign('list', $list);
        return $this->fetch();
    }

    public function info()
    {
        $info = $this->wxapp()->user->get(input('openid'));
        dump($info);
    }

    // 备注
    public function remark()
    {
        if (request()->isAjax()) {
            $openid = input('openid');
            $remark = input('remark');
            $res = $this->wxapp()->user->remark($openid, $remark);
            $res ? $this->success('备注成功') : $this->error('错误');
            return false;
        }
        $this->error('错误');
    }

    // 拉黑
    public function block()
    {
        if (request()->isAjax()) {
            $openid = input('openid');
            $res = $this->wxapp()->user->block($openid);
            $res ? $this->success('拉黑成功') : $this->error('拉黑失败');
        }
    }

    // 取消拉黑
    public function unblock()
    {
        if (request()->isAjax()) {
            $openid = input('openid');
            $res = $this->wxapp()->user->unblock($openid);
            $res ? $this->success('取消成功') : $this->error('取消失败');
        }
    }

    // 黑名单
    public function blacklist()
    {
        if (request()->isAjax()) {
            $list = $this->wxapp()->user->blacklist();
            $this->success('成功', '', $list);
        }
    }
}